package cn.com.infohold.test.json;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ResourceBundle;

import org.junit.Test;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;

public class GsonDemo {
	public static void main(String[] args) {
		
		JsonArray ja = new JsonArray();
		JsonObject jo = new JsonObject();
	}
	@Test
	public void testToJson(){
		People p = new People();
		p.setName("xxx");
		p.setAge(23);
		p.setJob("it");
		p.setHobbies(new String[]{"fitness","music"});
		Address addr = new Address();
		addr.setProvince("hubei");
		addr.setCity("tm");
		p.setAddress(addr);
		Gson gson = new Gson();
		String str = gson.toJson(p);
		System.out.println(str);
	}
	
	@Test
	public void testFromJson() throws JsonSyntaxException, JsonIOException, FileNotFoundException{
		
		Gson gson = new Gson();
		People p = gson.fromJson(new FileReader("src/cn/com/infohold/test/json/me.json"), People.class);
		System.out.println(p);
	}
	
}
